/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.nacos.naming.core.v2.client.manager;

import com.alibaba.nacos.naming.core.v2.client.Client;
import com.alibaba.nacos.naming.core.v2.client.ClientAttributes;

import java.util.Collection;

/**
 * 客户端管理器.
 *
 * @author xiweng.yy
 */
public interface ClientManager {

    /**
     * 创建客户端连接.
     *
     * @param clientId   客户端id
     * @param attributes 客户端属性集
     * @return 创建成功返回true，否则返回false
     */
    boolean clientConnected(String clientId, ClientAttributes attributes);

    /**
     * 创建客户端连接.
     *
     * @param client 新客户端
     * @return 创建成功返回true，否则返回false
     */
    boolean clientConnected(Client client);

    /**
     * 创建同步客户端连接.
     *
     * @param clientId   客户端id
     * @param attributes 客户端属性集
     * @return 创建成功返回true，否则返回false
     */
    boolean syncClientConnected(String clientId, ClientAttributes attributes);

    /**
     * 关闭客户端连接.
     *
     * @param clientId 客户端id
     * @return 关闭成功返回true，否则返回false
     */
    boolean clientDisconnected(String clientId);

    /**
     * 通过客户端id获取客户端.
     *
     * @param clientId 客户端id
     * @return 客户端
     */
    Client getClient(String clientId);

    /**
     * 判断客户端是否存在.
     *
     * @param clientId 客户端id
     * @return 存在返回true，否则返回false
     */
    boolean contains(final String clientId);

    /**
     * 获取所有客户端id集合.
     *
     * @return 客户端id集合
     */
    Collection<String> allClientId();

    /**
     * 判断客户端是否由当前服务器负责.
     *
     * @param client 客户端
     * @return 由当前服务器负责返回true，否则返回false
     */
    boolean isResponsibleClient(Client client);

    /**
     * 验证客户端.
     *
     * @param clientId 客户端id
     * @return 客户端有效返回true，否则返回false.
     */
    boolean verifyClient(String clientId);
}
